//
//  ZLAccountModel.swift
//  新浪微博
//
//  Created by 朱玉龙 on 9/27/16.
//  Copyright © 2016 朱玉龙. All rights reserved.
//

import UIKit

class ZLAccount: NSObject,NSCoding {
    //令牌
    var access_token: String?
    
    var expires_in: Int = 0 {
        
        didSet {
            
            expires_date = Date(timeIntervalSinceNow: (Double(expires_in)))
        }
    }
    //过期时间
    var expires_date: Date?
    
    var uid: String?
    
    var name: String?
    
    var avatar_large: String?
    
    
    init(dict: [String: Any]) {
        super.init()
        
        setValuesForKeys(dict)
    }
    
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) { }
    
    
    required init?(coder aDecoder: NSCoder) {
        access_token =  aDecoder.decodeObject(forKey: "access_token") as! String?
        expires_date = aDecoder.decodeObject(forKey: "expires_date") as! Date?
        uid = aDecoder.decodeObject(forKey: "uid") as! String?
        name = aDecoder.decodeObject(forKey: "name") as! String?
        avatar_large = aDecoder.decodeObject(forKey: "avatar_large") as! String?
    }
    
    func encode(with aCoder: NSCoder) {
        
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(expires_date, forKey: "expires_date")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(name,forKey:"name")
        aCoder.encode(avatar_large, forKey: "avatar_large")
    }
    




}
